package dongshi.daddy.dongsrmutitidatasoucespringbootstarter.model;

/**
 * 封装数据库连接信息的实体
 */
public class MyDbConnectionInfo {
    private int time = 400;
    /**
     * 数据源路由键，该值对应于配置文件中的routeKey，用来标示具体的数据源
     */
    private String routingKey;

    /**
     * 数据库地址
     */
    private String host;

    /**
     * 数据库端口
     */
    private String port;

    /**
     * 数据库用户名
     */
    private String username;

    /**
     * 数据库密码
     */
    private String password;

    /**
     * 数据库名称
     */
    private String database;

    public String getRoutingKey() {
        return routingKey;
    }

    public void setRoutingKey(String routingKey) {
        this.routingKey = routingKey;
    }

    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public String getPort() {
        return port;
    }

    public void setPort(String port) {
        this.port = port;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getDatabase() {
        return database;
    }

    public void setDatabase(String database) {
        this.database = database;
    }

    /**
     * 构造数据库链接URL
     * @return 数据库链接URL
     */
    public String buildJdbcUrl() {
        return String
                .format("jdbc:mysql://%s:%s/%s?serverTimezone=Asia/Shanghai&zeroDateTimeBehavior=CONVERT_TO_NULL&characterEncoding=utf8&allowMultiQueries=true&useAffectedRows=true", this.host, this.port, this.database);
    }
}
